//不要给我WA WA 叫
//一定AC
//author:Return.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iomanip>
#include <climits>
#define int long long 
#define x first 
#define y second 
using namespace std;
const int N = 1e5 + 10;
//int a[N];

// 检查是否可以在最多 k 次运输中运输所有货物，给定的最大载重量为 X
bool check(const vector<int> &a,int n,int k,int X)
{
    int cnt = 1;
    int cur_w = 0;
    for(int i = 0; i < n; i++)
    {
        if(cur_w + a[i] > X)
        {
            cnt++;
            cur_w = a[i];
            if(cnt > k || a[i] > X)
            {
                return false;
            }
        }
        else cur_w += a[i];
    }
    return true;
}
void solve()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    int l = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        l = max(l,a[i]);
    }
    int r = 1e16;
    while(l < r)
    {
        int mid = (r + l) / 2;
        if(check(a,n,k,mid))
        {
            r = mid;
        }
        else l = mid + 1;
    }
    cout << l << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t;
    cin >> t;
    while(t -- )  solve();
    return 0;
}
